<template lang="pug">
	include /pugs/item.pug
</template>
<script>
	const moment = require('moment')

	module.exports = {
		mixins: [
			require('mixin/rpc'),
			require('mixin/filesize'),
		],
		props: ['d'],
		data () {
			return {
				detail: false,
			}
		},
		methods: {
			remove () {
				this.d.remove().then(() => {
					this.$router.go({
						name: 'index',
					})
				})
			},
			toggleStatus (d) {
				if (d.status === 'active') {
					this.d.pause()
				}

				if (d.status === 'paused') {
					this.d.unpause()
				}

				if (d.status === 'error') {
					this.d.reAddUris()
				}
			},
			durationHumanize: restTime => {
				if (restTime === 0) return '∞'
	
				return moment.duration(
					restTime,
					'seconds'
				).humanize()
			},
		},
	}
</script>